package model

import (
	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:char(11);not null"`
	Password string `gorm:"type:varchar(32);not null"`
}

func (u *User) FindUserByMobile(db *gorm.DB, mobile string) error {
	return db.Debug().Where("mobile=?", mobile).First(u).Error
}
func (u *User) UserAdd(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) FindUserById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(u).Error
}

type Goods struct {
	gorm.Model
	GoodsName  string  `gorm:"type:varchar(30);not null"`
	GoodsPrice float32 `gorm:"type:decimal(10,2);not null"`
	UserId     int64   `gorm:"type:int;not null"`
}

func (g *Goods) GoodsAdd(db *gorm.DB) error {
	return db.Debug().Create(g).Error
}
